SRCDIR := ./src

OBJDIR := ./obj

INCS := $(foreach dir,${SRCDIR},-I${dir})
SRCS := $(foreach dir,$(SRCDIR),$(wildcard $(dir)/*.cc))
OBJS := $(patsubst %.cc,$(OBJDIR)/%.o,$(SRCS))

Thompson : ${OBJS}
	clang++ $(OBJS) -o bin/Thompson -O2 -std=c++11

$(OBJDIR)/%.o : %.cc
	mkdir -p $(dir $@)
	clang++ -c $(INCS) $< -o $@ -O2 -std=c++11

.PHONY: clean,lexer,parser,run
lexer: Thompson.l
	flex -o src/Thompsonlex.cc Thompson.l

parser: Thompson.y
	
	bison -dv Thompson.y
	mv Thompson.tab.c src/Thompson.tab.cc
	mv Thompson.tab.h src/Thompson.tab.h
	sed -i '1s/^/#include \"astnodes.h\"/' src/Thompson.tab.h

clean:
	rm -r ${OBJDIR}/*
	rm -r bin/*
run:
	./bin/Thompson